﻿using CodeGenerator.Models;
using CodeGenerator.Template;
using CodeGenerator.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CodeGenerator.Generators
{
    internal class MVC3DALGenerator : Generator
    {
        public override void Generate(int projectId, string outputPath)
        {
            MetaData modelForDAL = new MetaData();
            modelForDAL.Models = this.GetClassesByProjectId(projectId);
            modelForDAL.Project = this.GetProjectByProjectId(projectId);

            List<LookupClassModel> list = this.GetLookupClass(modelForDAL.Models);

            Generate(modelForDAL, list, outputPath);
        }

        public void Generate(MetaData modelForDAL, List<LookupClassModel> list, string outputPath)
        {
            if (!(modelForDAL.Models == null || modelForDAL.Project == null || list == null))
            {
                outputPath = Path.Combine(outputPath, modelForDAL.Project.ProjectName);
                DirectoryExt.CreateIfMissing(outputPath);

                GenerateFiles(modelForDAL, list, "DAL.Dal", outputPath);
                GenerateFiles(modelForDAL, list, "DAL.Entities", outputPath);
                GenerateFiles(modelForDAL, list, "DAL.Mappers", outputPath);
                GenerateFiles(modelForDAL, list, "DAL.Models", outputPath);
                GenerateFiles(modelForDAL, list, "DAL.Properties", outputPath);
            }
        }
    }
}
